poly_fn = 'cartoon.poly'
txt_fn = 'cartoon.txt'

poly_fh = open(poly_fn, 'r')
txt_fh = open(txt_fn, 'w')

piece_idx = 1

nb_kinds = int(poly_fh.readline())

for piece_idx in range(0, nb_kinds):
    nb_vtx = int(poly_fh.readline())
    txt_fh.write("PIECE %d\n" %(piece_idx+1))
    txt_fh.write("QUANTITY\n")
    repetition = 3
    txt_fh.write("%d\n" %(repetition))
    txt_fh.write("NUMBER OF VERTICES\n")
    txt_fh.write("%d\n" %(nb_vtx))
    txt_fh.write("VERTICES (X,Y)\n")
    for vtx_idx in range(0, nb_vtx):
        coord_line = poly_fh.readline()
        txt_fh.write(coord_line)
    txt_fh.write('\n')
    
poly_fh.close()
txt_fh.close()
    
